import { combineReducers, createStore } from "redux";


//  reducer  --> 状态处理器 , 可以单独放到其他文件夹中，这里演示，没必要分开
//参考 combineReducer : https://www.bilibili.com/video/BV1fw411d7R5?p=56&spm_id_from=pageDriver


/*
const myReducer = (preState,action)=> {
  //前一个状态 和 回调

  return preState
}

const store = createStore(myReducer);

*/
const reducer1 = (pre={color:'red'},action) => {
  console.log('current= ',pre)
   if(pre.color=='red') {
     return {
       color:'yellow'
     }
   }
   return {
     color:'red'
   }
}
const reducer2 = (pre={},action) => {
  return pre
}
// // 多个 reducer 需要合并
const reducer = combineReducers({
    reducer1,
  //  reducer2
})

const store = createStore(reducer)

export default store


/*
store.dispatch()

store.subscribe()
可以实现一个订阅发布功能


*/